package com.xxxx.portal.service.impl;

import com.xxxx.common.result.RespBean;
import com.xxxx.common.utils.MD5Util;
import com.xxxx.portal.mapper.UserMapper;
import com.xxxx.portal.service.UserService;
import com.xxxx.portal.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //注册用户
    @Override
    public RespBean registerUser(UserVo userVo) {
        //查询数据库是否有该姓名的用户
        Integer m=nameIsExist(userVo.getUserName());
        if(m>0){
            System.out.println("用户名已存在！");
            return RespBean.error("用户名已存在！");
        }
        //数据库中没有该用户，则将用户输入密码进行加密，得到新的加密后密码，放入数据库中
        String password = MD5Util.generate(userVo.getPassword());
        userVo.setPassword(password);
        Integer i = userMapper.insertUser(userVo);
        return i>0?RespBean.success("注册成功！"):RespBean.error("注册失败！");
    }
    //判断数据库中是否存在该姓名的用户
    @Override
    public Integer nameIsExist(String uid) {
        return userMapper.checkName(uid);
    }
}
